package bus;

import dao.AdminDao;
import dao.StudentDao;
import dao.TeacherDao;
import dto.AdminDto;
import dto.StudentDto;
import dto.TeacherDto;

public class UpdateUserBus {

	public static String changePasswordStudent(StudentDto student,
			String newPass) {

		String response = "";

		StudentDao studentDao = new StudentDao();
		StudentDto oldStudent = studentDao.getStudentById(student.getId());
		if (oldStudent != null) {
			if (oldStudent.getPassword().equals(student.getPassword())) {

				oldStudent.setPassword(newPass);
				response = studentDao.updateStudent(oldStudent);
			} else
				response = "Old password is incorrect!";
		} else
			response = "Not found student ID is \"" + student.getId() + "\"";

		return response;
	}

	public static String changePasswordTeacher(TeacherDto teacher,
			String newPass) {

		String response = "";

		TeacherDao TeacherDao = new TeacherDao();
		TeacherDto oldTeacher = TeacherDao.getTeacherById(teacher.getId());
		if (oldTeacher != null) {
			if (oldTeacher.getPassword().equals(teacher.getPassword())) {

				oldTeacher.setPassword(newPass);
				response = TeacherDao.updateTeacher(oldTeacher);
			} else
				response = "Old password is incorrect!";

		} else
			response = "Not found teacher ID is \"" + teacher.getId() + "\"";

		return response;
	}

	public static String changePasswordAdmin(AdminDto admin, String newPass) {

		String response = "";

		AdminDao AdminDao = new AdminDao();
		AdminDto oldAdmin = AdminDao.getAdminById(admin.getId());
		if (oldAdmin != null) {
			if (oldAdmin.getPassword().equals(admin.getPassword())) {

				oldAdmin.setPassword(newPass);
				response = AdminDao.updateAdmin(oldAdmin);
			} else
				response = "Old password is incorrect!";

		} else
			response = "Not found admin ID is \"" + admin.getId() + "\"";

		return response;
	}

}
